from selenium import webdriver
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common import keys
from selenium.webdriver.common.keys import Keys

wd = webdriver.Chrome()
wd.get("http://172.16.60.14/login")
wd.implicitly_wait(10)

wd.find_element_by_xpath("//../span[text() = '用户中心登录']").click()

# 输入邮箱
wd.find_element_by_xpath("//input[@placeholder= '邮箱']").send_keys("admin@forensix.cn")

# 输入密码
wd.find_element_by_xpath("//input[@placeholder = '密码']").send_keys("123456")

# 点击“授权并登录”按钮
wd.find_element_by_xpath("//span[text() = '授权并登录']").click()

time.sleep(3)

js = "window.open('http://172.16.60.14/testpaper/detail/competition/5f50b9c4de185d3375a46a34')"
wd.execute_script(js)




handles = wd.window_handles

wd.switch_to.window(handles[-1])
wd.find_element_by_xpath('//span[text()="添加题目"]').click()
ele = wd.find_element_by_css_selector('[placeholder="请输入题干"]')
ele.send_keys("13254")
#.key_down(Keys.SHIFT).key_down(Keys.HOME)\
ele.send_keys(Keys.CONTROL,'b')

